package Controller::Sweet;

use strict;
use warnings;

=head1 NAME

Controller::Sweet - SweetPea Introduction and Welcome Page

=head2 welcome

This function displays a simple information page the application defaults to before development.
This module should be removed before development.

=cut

sub welcome {
    my $s = shift;
    
    #header
    $s->html(<<EOF);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>SweetPea is Alive and Well - SweetPea, the PnP Perl Web Application Framework</title>
EOF
    
    #stylesheet
    $s->html(<<EOF);
        <style type="text/css">
            body
            {
                font-family:    Bitstream Vera Sans,Trebuchet MS,Verdana,Tahoma,Arial,helvetica,sans-serif;
                color:          #818F08;
            }
            h1
            {
                background-color:#818F08;
                color:#FFFFFF;
                display:block;
                font-size:0.85em;
                font-weight:normal;
                left:0;
                padding-bottom:10px;
                padding-left:15px;
                padding-right:10px;
                padding-top:10px;
                position:absolute;
                right:0;
                top:0;
                margin: 0px;
            }
            h2
            {
                background-color:#EFEEEE;
                font-size:1em;
                padding-bottom:5px;
                padding-left:5px;
                padding-right:5px;
                padding-top:5px;
            }
            #container
            {
                position:absolute;
                font-size:0.8em;
                font-weight:normal;
                padding-bottom:10px;
                padding-left:15px;
                padding-right:10px;
                padding-top:10px;
                left:0;
                right:0;
                top:40px;
            }
            .issue
            {
                color: #FF0000;
            }
            .highlight
            {
                background-color:#EFEEEE;
                padding:1px;
            }
        </style>
    </head>
    <body>
    <h1>Welcome Young GrassHopper, SweetPea is working.</h1>
    <div id="container">
EOF
    
    #//////////////
    # check manifest if available
    my $path = $s->application->{path};
    if ( -e "$path/manifest" )
    {
        open MF, "$path/manifest" or die print "Error reading $path/manifest, $!";
        my @files_and_dirs = <MF>;
        close MF or die print "Error closing $path/manifest, $!";
        foreach (@files_and_dirs)
        {
            chomp;
            my $file = "$path/$_";
            $s->html( "<span class=\"issue\">$_ is not accessible.</span><br/>\n" ) unless -e $file || $file =~ /\.make/;
        }
    }
    # warn about the danger of leaving .make on a production system
    $s->html( "<span class=\"issue\">.make should be removed after development.</span><br/>\n" ) if -e "$path/.make";
    #//////////////
    
    #//////////////
    $s->html( "<div class=\"section\">" );
    $s->html( "<h2>Application Details</h2>" );
    $s->html( "<span>SweetPea is running under Perl <span class=\"highlight\">$]</span> and is located at <span class=\"highlight\">$path</span></span><br/>" );
    $s->html( "</div>" );
    #//////////////
    
    $s->html(<<EOF);
    </div>
    </body>
</html>
EOF

}

=head1 AUTHOR

Al Newkirk al.newkirk@awnstudio.com

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
